{include file="public/nheader"}
<div class="layui-fluid layui-bg-white">
    <form action="{:url()}" class="layui-form layui-form-fixed">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>品牌
            </label>
            <div class="layui-input-block">
                <select name="type" lay-verify="" lay-filter="type">
                    <option value="">选择品牌</option>
                    {foreach $pinpai as $pai}
                    <option value="{$pai.type}" {if !empty($row['type']) && $row['type']==$pai.type}selected {/if} {if
                        !empty($row.id)}disabled{/if}>{$pai.pinpai}
                        {/foreach}
                    </option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red"> </font>运营人姓名
            </label>
            <div class="layui-input-block">
                <input type="text" id="yyname" name="yyname" value="{$row.yyname|default=''}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>广告主ID(请确保广告主ID存在且正确)
            </label>
            <div class="layui-input-block">
                <input type="text" id="ly" name="ly" value="{$row.ly|default=''}" required="" lay-verify="required"
                    autocomplete="off" class="layui-input">
                <!-- <select name="ly" lay-verify="">
                    
                    {foreach $ptlaiyuan as $key => $pai}
                    <option value="{$key}" {if empty($row['ly']) || $row['ly']==$key}selected{/if}>{$pai}
                        {/foreach}
                    </option>
                </select> -->
            </div>
        </div>
        <div class="layui-form-item" id="eclaiyuan">
            <label class="layui-form-label">
                <font color="red">* </font>EC来源(添加请先选择品牌并且确保汇营销系统规则内包含此来源，否则不会自动分配)
            </label>
            <div class="layui-input-block">
                <select name="ecRcm" lay-verify="">
                    <option value="">EC来源</option>
                    {foreach $eclaiyuan as $pai}
                    <option value="{$pai.ecid}" {if !empty($row['ecRcm']) && $row['ecRcm']==$pai.ecid}selected{/if}>
                        {$pai.ecname}{if !empty($pai.ecgroupName)}({$pai.ecgroupName}){/if}
                        {/foreach}
                    </option>
                </select>
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <input type="hidden" value="{$row.id|default='0'}" name="id" />
            <button class="layui-btn" lay-filter="submitIframe" type="button" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">取消</button>
        </div>
    </form>
</div>
{include file="public/nfooter"}
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        form.on('checkbox(father)', function (data) {
            if (data.elem.checked) {
                $(data.elem).parent().next('div').find('input').prop("checked", true);
                form.render();
            } else {
                $(data.elem).parent().next('div').find('input').prop("checked", false);
                form.render();
            }
        });
        form.on('select(type)', function (data) {
            var type = data.value;
            //发异步，把数据提交给php
            $.ajax({
                type: 'get',
                url: '/base/getecsource',
                data: { type: type },
                success: function (res) {
                    if (res.code == 0) {
                        var str = '<select name="ecRcm" data-area="" lay-filter="ecRcm" lay-search><option value="">EC来源</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.ecid;
                            str += '">' + obj.ecname;
                            if (obj.ecgroupName) {
                                str += "(" + obj.ecgroupName + ")";
                            }
                            str += '</option>';
                        });
                        str += '</select>';
                        $('#eclaiyuan .layui-input-block').html(str);
                        form.render();
                    } else {
                        layer.msg('获取EC来源失败', { icon: 2, time: 1000 });
                    }
                }
            });
            return false;
        });
    });
</script>